package control;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.FacilityDTO;
import model.FacilitySearchbyTypeDTO;
import business.BookingManager;

/**
 * Servlet implementation class SearchAvailableFacilitybyType
 */
// @WebServlet(name = "safbtype", urlPatterns = { "/safbtype" })
public class SearchAvailableFacilitybyType extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public SearchAvailableFacilitybyType() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request, response);
	}

	private void doProcess(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String type = request.getParameter("facilityType");
		String des = request.getParameter("description");
		String name = request.getParameter("name");
		String capacity = request.getParameter("capacity");
		if ( type.trim().equalsIgnoreCase("")&& des.trim().equalsIgnoreCase("")
				&& name.trim().equalsIgnoreCase("")
				&& capacity.trim().equalsIgnoreCase("")) {
			RequestDispatcher rd = request.getRequestDispatcher("/Notfind.jsp");
			rd.forward(request, response);
		}
		
		else {
			 if (type.trim()!= "" || des.trim()!= "" || name.trim()!= "" ||
			 capacity.trim()!= "")
			 {

			FacilitySearchbyTypeDTO facility = new FacilitySearchbyTypeDTO();
			facility.setFacilityType(type);
			facility.setDescription(des);
			facility.setFacilityName(name);
			facility.setCapacity(capacity);

			BookingManager bm = new BookingManager();
			ArrayList<FacilityDTO> facilitylist = bm
					.findfacilityByCriteria(facility);
			request.setAttribute("searchlist", facilitylist);
			RequestDispatcher rd = request
					.getRequestDispatcher("/SearchPage.jsp");
			rd.forward(request, response);
			 }
		}
	   
	  
		}
	
	
		
		
	}
		
	

